package com.example.a2007dou_shop.adapter

import android.widget.ImageView
import androidx.core.view.isVisible
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.a2007dou_shop.R
import com.example.a2007dou_shop.entity.VideoEntity
import com.example.a2007dou_shop.entity.VideosEntity
import com.example.a2007dou_shop.entity.VideosEntityResult
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer

class VideoAdapter(list: MutableList<VideosEntity>):BaseMultiItemQuickAdapter<VideosEntity,BaseViewHolder>(list) {
    init {
        addItemType(0, R.layout.item_video_nornal)
        addItemType(1,R.layout.item_video_zhibo)
        addItemType(2,R.layout.item_video_zhibo)
        addItemType(5,R.layout.item_video_zhibo)
    }
    override fun convert(holder: BaseViewHolder, item: VideosEntity) {
        when(item.itemType){
            0->{
               //设置文字
                holder.setText(R.id.tv_title,item.caption)
                holder.setText(R.id.tv_user,item.authname)
                Glide.with(context).load(item.headpath).into(holder.getView(R.id.iv_user))
                val gsy = holder.getView<StandardGSYVideoPlayer>(R.id.gsy)
                gsy.setUp(item.videopath,true,"")//设置播放资源
                gsy.startPlayLogic()//开始播放
                gsy.backButton.isVisible = false//隐藏返回按钮的


            }
            1,2,5->{
                holder.setText(R.id.tv_title,item.caption)
                holder.setText(R.id.tv_user,item.authname)
                val gsy = holder.getView<StandardGSYVideoPlayer>(R.id.gsy)
                //Glide.with(context).load(item.videomainimg).into(gsy.thumbImageView as ImageView)//设置视频缩略图
                gsy.setUp(item.videopath,true,"")//设置播放资源
                gsy.startPlayLogic()//开始播放
                gsy.backButton.isVisible = false//隐藏返回按钮的
            }
        }
    }
}